package com.fairytask.utils
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	public class SWFClass extends EventDispatcher
	{
		private var SWFBytes:Class;
		protected static var loader:flash.display.Loader;
		
		public function SWFClass()
		{
			super();
			loader = new Loader();
			loader.loadBytes(new ByteArray());
			return;
		}
		
		internal function loadedHandler(arg1:Event):void
		{
			dispatchEvent(new Event(Event.COMPLETE));
			return;
		}
		
		internal function progressHandler(arg1:ProgressEvent):void
		{
			dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, arg1.bytesLoaded, arg1.bytesTotal));
			return;
		}
		
		public function load(arg1:String):void
		{
			if (loader) 
			{
				dispatchEvent(new Event(Event.COMPLETE));
				return;
			}
			loader = new flash.display.Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.loadedHandler);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, this.progressHandler);
			loader.load(new URLRequest(arg1));
			return;
		}
		
		public static function get(arg1:String, ... rest):*
		{
			if (loader == null) 
			{
				return null;
			}
			var loc1:*=loader.contentLoaderInfo.applicationDomain.getDefinition(arg1) as Class;
			if (loc1 == null) 
			{
				return null;
			}
			var loc2:*=rest.length;
			switch (loc2) 
			{
				case 0:
				{
					return new loc1();
				}
				case 1:
				{
					return new loc1(rest[0]);
				}
				case 2:
				{
					return new loc1(rest[0], rest[1]);
				}
			}
			return;
		}
	}
}